home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 4 #1 & #2 / IMG 34 JanFeb 1996.iso / More Goodies / Cheaters, Editors, et al. / WolfEdit 1.1B ƒ / Level Format < prev    next >
Text File  |  1995-09-16  |  12KB  |  365 lines

  1.         Wolfenstein 3D First Encounter Level Format
  2.         ===========================================
  3.  
  4.                         Greg Ewing
  5.                 greg@cosc.canterbury.ac.nz
  6.  
  7. Here is a summary of what I have learned about the format of the level 
  8. resources used by Wolfenstein 3D First Encounter.
  9.  
  10. 1. Map List resource
  11. --------------------
  12.  
  13. The Map List is in BRGR resource 146.  It begins with a 2-word header:
  14.  
  15. Offset    Size    Description
  16.     0    word    Number of levels
  17.     2    word    Resource ID of the first level
  18.  
  19. Following this is a 5-word entry for each level:
  20.  
  21.     0    word    Next level (offset from first level ID)
  22.     2    word    Alternate next level
  23.     4    word    Par time (seconds)
  24.     6    word    Major floor number
  25.     8    word    Minor floor number
  26.  
  27. 2. Level resource
  28. -----------------
  29.  
  30. The levels themselves are also kept in BRGR resources.  The ID of the first 
  31. level resource is determined by the map list as described above.  The 
  32. original levels use IDs 200 and upwards.
  33.  
  34. The level resource consists of a fixed-length part followed by a 
  35. variable-length part.  The fixed-length part can be further subdivided into 
  36. a map and a sound area table, and the variable-length part into a header, 
  37. an object table and a BSP tree.
  38.  
  39. 2.1 Map
  40. -------
  41.  
  42. The map section is 4096 bytes long, organised as a 64 by 64 grid.  Each 
  43. byte in the map represents either a solid block, a door or an empty space.  
  44. If bit 7 of the byte is 1, then it represents a solid block or door, and 
  45. the rest of the bits determine what kind of wall or door it is.
  46.  
  47. If bit 7 is 0, the byte contains a room number.  A room is a contiguous 
  48. space which is completely divided off from other rooms by walls or doors.  
  49. There may be up to 64 rooms, numbered 0 to 63.  Each byte in the map 
  50. representing an empty space contains the room number to which the space 
  51. belongs.
  52.  
  53. 2.2 Sound Area table
  54. --------------------
  55.  
  56. This is a 64-byte table containing a sound area number for each room.  When 
  57. you fire your gun, guards in rooms belonging to the same sound area can 
  58. hear you.  If they're not "shoot only on sight" guards, they will seek you 
  59. out.
  60.  
  61. WolfEdit 1.1 does not provide any way of setting sound areas; each room is 
  62. placed in a separate sound area.  (Note, however, that an area separated 
  63. from a room by a secret door is considered part of the same room.)
  64.  
  65. 2.3 Header of variable-length part
  66. ----------------------------------
  67.  
  68. The variable-length part begins with a 4-word header.  Entries marked with 
  69. * are stored in little-endian byte order (least significant byte first).
  70.  
  71.     0    word    Number of objects
  72.     2    word    Offset from start of resource to object table
  73.     4    word    Number of entries in BSP tree
  74.     6    word    Offset from start of resource to BSP tree
  75.  
  76. 2.4 Object table
  77. ----------------
  78.  
  79. The object table contains an entry for each object appearing on the level.  
  80. Each entry is either 3 or 4 bytes long, depending on the object type.
  81.  
  82.     0    byte    x-coordinate of map cell (0 to 63)
  83.     1    byte    y-coordinate of map cell (0 to 63)
  84.     2    byte    Object type
  85.  
  86. If the object type is $62, then the object is a secret door.  In the map, a 
  87. secret door appears as an empty space, and there is an extra byte in the 
  88. object table entry containing the wall type:
  89.  
  90.     3    byte    Wall type of secret door (object type $62 only)
  91.  
  92. 2.5 BSP tree
  93. ------------
  94.  
  95. 2.5.1 About the BSP tree
  96.  
  97. A Binary Space Partitioning or BSP tree is used to divide the map space up 
  98. into portions in such a way that the rendering engine can efficiently 
  99. determine which parts are visible.
  100.  
  101. The BSP tree consists of two types of nodes, terminal and non-terminal.  
  102. Each node corresponds to some rectangular portion of the map.  A 
  103. non-terminal node is further subdivided into two child nodes.  A terminal 
  104. node is not subdivided any further and has no children; it is a "leaf" of 
  105. the tree.
  106.  
  107. A terminal node consists of a collection of segments.  A segment represents 
  108. part of a wall - a boundary between an empty and a filled-in region of the 
  109. map.
  110.  
  111. The coordinate system used to describe segments has twice the resolution of 
  112. the map cell coordinate system used in the object table.  Furthermore, 
  113. instead of referring to cells, segment coordinates refer to the dividing 
  114. lines between cells.  So, whereas cell coordinates range from 0 to 63, 
  115. segment coordinates range from 0 to 128.  Even segment coordinates 
  116. correspond to the lines running between map cells; odd segment coordinates 
  117. refer to lines which pass through the middle of map cells.  (The reason for 
  118. this will become clear later.)
  119.  
  120. Each segment is described by three coordinates.  For segments running 
  121. east-west these are its position in the y direction and the x-coordinates 
  122. of its two endpoints.  For segments running north-south, the roles of x and 
  123. y are reversed.
  124.  
  125. Each segment also faces in a particular direction.  An east-west segment 
  126. can face either north or south, and a north-south segment can face either 
  127. east or west.  The direction a segment faces determines from which side it 
  128. will be visible; the rendering engine doesn't bother drawing segments which 
  129. are facing away from you.
  130.  
  131. A terminal node of the tree contains a collection of segments such that no 
  132. segment can obscure part of any other segment from any viewing position.
  133.  
  134. 2.5.2 Format of the BSP tree
  135.  
  136. The BSP tree consists of a sequence of 6-byte entries, numbered from 0.  
  137. The root node of the tree begins at entry 0.
  138.  
  139. Each non-terminal node takes up one entry structured as follows:
  140.  
  141.     0    byte    Split coordinate
  142.     
  143.                         For an east-west split, this is the y-coordinate
  144.                         of the splitting line; for north-south, the
  145.                         x-coordinate.
  146.                         
  147.     1    byte    Flags    Bit 7 of this byte is 0, indicating a non-terminal
  148.                         node. Bit 0 indicates the direction along which
  149.                         the space covered by this node is split to create
  150.                         the subspaces of its child nodes. 0 means the
  151.                         splitting line runs east-west, 1 north-south.
  152.                         
  153.     2    word*    First child
  154.     
  155.                         Entry number of the first child node. The subspace
  156.                         covered by this child is the one with coordinates
  157.                         *greater* than that of the splitting line.
  158.                         
  159.     4    word*    Second child
  160.     
  161.                         Entry number of the other child node.
  162.  
  163. The coordinates of the region covered by each node are not explicitly 
  164. stored in the node; rather, they are implicit in the coordinates of the 
  165. splitting lines at each step, and the fact that the root node covers the 
  166. whole of the map.
  167.  
  168. Each terminal node takes up one entry for each segment as follows:
  169.  
  170.     0    byte    Segment position
  171.     
  172.                         For an east-west (or north-south) segment, this is 
  173.                         the positition of the segment in the y (or x) 
  174.                         direction.
  175.                         
  176.     1    byte    Flags    Bit 7 of this byte is 1, indicating a terminal
  177.                         node. Bit 6 is set to 1 if this is the last segment
  178.                         belonging to this node; 0 if more are to follow.
  179.                         Bits 1 and 0 indicate the orientation of the
  180.                         segment:
  181.                         
  182.                             00    North-south, facing east
  183.                             01    East-west, facing south
  184.                             10    North-south, facing west
  185.                             11    East-west, facing north
  186.                             
  187.     2    byte    Start coordinate
  188.     3    byte    End coordinate
  189.     
  190.                         For east-west (or north-south) segments, these
  191.                         are the x (or y) coordinates of the segment's
  192.                         endpoints.
  193.                         
  194.     4    byte    Map row/column
  195.     
  196.                         For east-west segments, this is the map cell
  197.                         coordinate (0 to 63) of the map row containing
  198.                         the wall block immediately behind the segment.
  199.                         For north-south segments, it is the column
  200.                         number plus 64.
  201.                         (For segments associated with doors, this byte
  202.                         has a different interpretation - see below.)
  203.                         
  204.     5    byte    Room number
  205.     
  206.                         This is the room number of the room into which
  207.                         the segment faces.
  208.  
  209. 2.6 Doors
  210. ---------
  211.  
  212. A door is represented by an entry in both the map and the object table, the 
  213. object having the same code as the map entry with bit 7 set to 0.  Bit 0 of 
  214. the door code indicates the direction of the door: 0 for a doorway leading 
  215. east-west, 1 for north-south.
  216.  
  217. Associated with a door are four special segments, one each side of the door 
  218. facing inwards, and one along each face of the door itself (the sliding 
  219. part).  The latter two are positioned in the middle of the map cell 
  220. containing the door.
  221.  
  222. The side segments have byte 4 of the segment entry set to $80.  The sliding 
  223. segments have this byte set to $80 plus the door number: each door on a 
  224. level has a unique number from 1 upwards.
  225.  
  226. 2.7 Lifts
  227. ---------
  228.  
  229. The lift control panel and the side panels with hand railings are 
  230. represented in the map by the same code ($8F).  If you are looking at the 
  231. east or west face of the block, it appears as a lift control panel; if you 
  232. are looking at the north or south face, it appears as a hand railing.
  233.  
  234. However, the lift control panel also has an object with a code of $64 at 
  235. the same location.  It is the presence of this object which causes the 
  236. block to behave like a lift when you operate it.  If this object is not 
  237. present, the control panel is just another piece of wall.  Conversely, 
  238. placing a $64 object on top of some other type of wall will make it behave 
  239. like a lift.  This could allow for some very unfair levels...
  240.  
  241. 2.8 Hidden passages
  242. -------------------
  243.  
  244. The secret blocks which move back when you push on them involve special 
  245. arrangements in the map, object table and BSP tree.  In the map, the 
  246. location of the secret block is an empty space, and the area to which it 
  247. leads is part of the same room as the area it leads from.
  248.  
  249. An object with code $62 is placed at this location: this is the object you 
  250. operate when you push on the block.  The object table entry for this object 
  251. has an extra byte appended, containing the wall code which would otherwise 
  252. have been placed in the map at that location.
  253.  
  254. The secret block has two segments associated with it.  One of them is 
  255. positioned on the outside of the block in its initial position, facing 
  256. towards the player as he stands in front of the block ready to push it.  
  257. The other segment is positioned on the other side of the block, but facing 
  258. in the same direction - in other words, it is in the place the first 
  259. segment would end up after the block had been pushed one map cell.  Byte 4 
  260. of both these segments refer to the block's initial location.
  261.  
  262. It is also necessary to place an ordinary block of the same type two cells 
  263. away in the direction of motion, i.e.  in the place where the secret block 
  264. will end up after it has been pushed.  If this is not done, not only will 
  265. the block vanish after opening, but for some strange reason it may not 
  266. display properly in its initial position.
  267.  
  268. 2.9 Map codes
  269. -------------
  270.  
  271. Here is a list of the codes which may be placed in the map for various 
  272. types of walls and doors.
  273.  
  274. 2.9.1 Wall codes
  275.  
  276. $81    Grey stone
  277. $82    Grey stone with archway and eagle emblem
  278. $83    Grey stone with swastika wall hanging
  279. $84    Grey stone with Hitler portrait
  280. $85    Wood panelling
  281. $86    Wood panelling with eagle emblem
  282. $87    Wood panelling with Hitler portrait
  283. $88    Wood panelling with purple cross
  284. $89    Blue stone
  285. $8A    Blue stone with cell door
  286. $8B    Red brick
  287. $8C    Red brick with eagle emblem
  288. $8F    Lift side wall or control panel
  289. $91    Metal plate
  290. $9A    Yellow stone with blood stain
  291. $9B    Yellow stone blocks
  292. $9D Concrete(?) blocks
  293.  
  294. 2.9.2 Door codes
  295.  
  296. $DA    Plain east-west
  297. $DB    Plain north-south
  298. $DD    Gold key north-south    (Note: there is no gold key east-west door!)
  299. $DE    Silver key east-west
  300. $DF    Silver key north-south
  301. $E0    Lift door east-west
  302. $E1    Lift door north-south
  303.  
  304. 2.10 Object codes
  305. -----------------
  306.  
  307. Here is a list of codes which may be placed in the object table.
  308.  
  309. 2.10.1 Player starting positions
  310.  
  311. $13    Facing north
  312. $14    Facing east
  313. $15    Facing south
  314. $16    Facing west
  315.  
  316. 2.10.2 Ornaments
  317.  
  318. $17    Puddle
  319. $18    Oil drum
  320. $19    Table
  321. $1A    Standard lamp
  322. $1B    Chandelier
  323. $1E    Tree
  324. $1F Flag pole
  325. $20    Pot plant
  326. $21    Urn
  327. $22    Bones
  328. $23    Ceiling light
  329. $24    Bowl
  330. $25    Suit of armour
  331. $26    Hanging cage
  332. $36    Water tub
  333. $37  Dog crap
  334.  
  335. 2.10.3 Useful items
  336.  
  337. $1C    Dog food
  338. $27    Gold key
  339. $28    Silver key
  340. $29 Backpack
  341. $2A    Ammunition box
  342. $2B    Food
  343. $2C First aid kit
  344. $2D    Ammunition clip
  345. $2E    Machine gun
  346. $2F    Gatling gun
  347. $34    Extra life
  348. $35  BigDickey
  349.  
  350. 2.10.4 Treasures
  351.  
  352. $30    Jewelled cross
  353. $31    Goblet
  354. $32    Treasure chest
  355. $33    Crown
  356. $34  Crap
  357.  
  358. 2.10.5 Enemies
  359.  
  360. $6C    Brown uniform
  361. $6E    Blue uniform
  362. $6F    Dog
  363. $71    Boss
  364. $7E    Brown uniform, waiting to ambush
  365.